//
//  BaseNavigationController.swift
//  QingLiuSwift
//
//  Created by xyanl on 2023/8/17.
//

import Foundation
import UIKit

class BaseNavigationController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // 监听手势
        interactivePopGestureRecognizer?.delegate = self
        // 向上滚动的时候, 不隐藏navigationBar
        hidesBarsOnSwipe = false
        // 设置导航栏的半透明效果，默认是true
        navigationBar.isTranslucent = true
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        // 隐藏tabBar
        viewController.hidesBottomBarWhenPushed = viewControllers.count > 0
        super.pushViewController(viewController, animated: animated)
    }
    
    // 重写这两个方法 修复、控制 preferredStatusBarStyle，否则方法无效
    override var childForStatusBarHidden: UIViewController? {
        // 状态栏隐藏与否
        return self.topViewController 
    }
    override var childForStatusBarStyle: UIViewController? {
        // 状态栏颜色
        return self.topViewController
    }
}

extension BaseNavigationController: UIGestureRecognizerDelegate {
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        if viewControllers.count == 0 {
            return false
        }
        return true
    }

    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        return false
    }
}

